Origin of discouraged perl idioms: &x(...) and sub x($$) { ... }

Posted by knorv on Stack Overflow See other posts from Stack Overflow or by knorv
Published on 2010-05-16T12:35:48Z Indexed on 2010/05/16 12:40 UTC
Read the original article Hit count: 129

Filed under:
|

In my perl code I've previously used the following two styles of writing which I've later found are being discouraged in modern perl:

# Style #1: Using & before calling a user-defined subroutine
&name_of_subroutine($something, $something_else);

# Style #2: Using ($$) to show the number of arguments in a user-defined sub
sub name_of_subroutine($$) {
  # the body of a subroutine taking two arguments.
}

Since learning that those styles are not recommended I've simply stopped using them.

However, out of curiosity I'd like to know the following:

  • What is the origin of those two styles of writing? (I'm sure I've not dreamt up the styles myself.)
  • Why are those two styles of writing discouraged in modern perl?
  • Have the styles been considered best practice at some point in time?

© Stack Overflow or respective owner

Related posts about perl

Related posts about coding-style